package com.PGD.model.vos
{
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	import mx.events.CollectionEvent;
	import mx.events.CollectionEventKind;
	
	import uranrus.persistence.BazManaged;
	import uranrus.persistence.BazManagedCollection;
	
	public class SlidePack extends BazManaged implements ISlidePack
	{
		
		
		private var _lastSaved:Date;
		[Bindable(event="lastSavedChange")]
		public function set lastSaved (value:Date):void
		{
			if (value != _lastSaved)
			{
				_lastSaved = value;
				dispatchEvent (new Event ("lastSavedChange"));
			}
		}

		public function get lastSaved ():Date
		{
			return _lastSaved;
		}


		
		private var _id:String;
		[Bindable(event="idChange")]
		override public function set id (value:*):void
		{
			if (value != _id)
			{
				_id = value as String;
				dispatchEvent (new Event ("idChange"));
				isDirty = true;
			}
		}

		override public function get id ():*
		{
			return _id;
		}

		private var _name:String;
		[Bindable(event="nameChange")]
		public function set name (value:String):void
		{
			if (value != _name)
			{
				_name = value;
				dispatchEvent (new Event ("nameChange"));
				isDirty = true;
			}
		}

		public function get name ():String
		{
			return _name;
		}

		
		private var _slides:BazManagedCollection;
		[Bindable(event="slidesChange")]
		public function set slides (value:ArrayCollection):void
		{
			if (value != _slides)
			{
				if (_slides)
				{
					_slides.removeEventListener
						(CollectionEvent.COLLECTION_CHANGE, onSlidesChange);
						_slides.removeEventListener(BazManagedCollection.PROPERTY_UPDATED_EVENT, slidePropertyChangeHandler)
						
				}
				_slides = new BazManagedCollection(value.source);
				if (_slides)
				{
					_slides.addEventListener
						(CollectionEvent.COLLECTION_CHANGE, onSlidesChange);
						_slides.addEventListener(BazManagedCollection.PROPERTY_UPDATED_EVENT, slidePropertyChangeHandler);
				}
				dispatchEvent (new Event ("slidesChange"));
			}
		}

		public function get slides ():ArrayCollection
		{
			return _slides;
		}

		private function onSlidesChange (event:CollectionEvent):void
		{
			if ((event.kind == CollectionEventKind.ADD) ||
				(event.kind == CollectionEventKind.REMOVE))
			{
				
				dispatchEvent (new Event ("slidesChange"));
				isDirty = true;
			}
		}
		private function slidePropertyChangeHandler(evt:Event):void
		{
			trace("one of my slides's info changed")
			dispatchEvent (new Event ("slidesChange"));
			isDirty = true;
		}














		public function clone():Object
		{
			return null;
		}

		
		
		
		private var _creationDate:Date;


		

		public function set creationDate(val:Date):void
		{
			_creationDate = val;
		}

		public function get creationDate():Date
		{
			return _creationDate;
		}
		
	}
}